package com.ias.agdis_r.util.sdcard;

import java.io.File;
import java.io.IOException;

import android.os.Environment;

/**
 * SD卡相关类
 * 
 * @author liuhuanlei
 * 
 */
public class SDcard {

	/**
	 * 判断SD卡是否存在
	 * 
	 * @return 存在：SD的根目录，不存在：null
	 */
	public static String getSDPATH() {
		File sdDir = null;
		boolean sdCardExist = Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED); // 判断sd卡是否存在
		if (sdCardExist) {
			sdDir = Environment.getExternalStorageDirectory();// 获取跟目录
		}
		return sdDir == null ? "" : sdDir.toString();

	}

	// sax-------

	/**
	 * 在SD卡上创建文件
	 * 
	 * @throws IOException
	 */
	public static File creatSDFile(String fileName) throws IOException {
		File file = new File(fileName);
		file.createNewFile();
		return file;
	}

	/**
	 * 在SD卡上创建目录
	 * 
	 * @param dirName
	 */
	public static boolean creatSDDir(String dirName) {
		File dir = new File(dirName);
		return dir.mkdir();
	}

	/**
	 * 判断SD卡上的文件夹是否存在
	 */
	public static boolean isFileExist(String fileName) {
		File file = new File(fileName);
		return file.exists();
	}

}